package com.yigang.service.impl;

import java.util.List;
import java.util.Map;

import com.yigang.dao.ShoppingcartMapper;
import com.yigang.entity.Shoppingcart;
import com.yigang.entity.ShoppingcartVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.yigang.dao.ShopingCartDao;
import com.yigang.service.ShopingCartService;

@Service
@Transactional
public class ShopingCartServiceImpl implements ShopingCartService {

    @Autowired
    private ShopingCartDao shopingCartDao;
    @Autowired
    private ShoppingcartMapper shoppingcartMapper;

    @Override
    public List<Map<String, Object>> getAllShopingCartById() {
        // TODO Auto-generated method stub

        return shopingCartDao.getAllShopingCartById();
    }

    @Override
    public int addCart(Shoppingcart shopingCart) {
        //如果之前添加过,则直接添加数量

        return shoppingcartMapper.insert(shopingCart);
    }

    @Override
    public int updateNumCart(Shoppingcart shopingCart) {
        return shoppingcartMapper.update(shopingCart);
    }

    @Override
    public int delCart(Shoppingcart shopingCart) {
        return shoppingcartMapper.delete(Long.valueOf(shopingCart.getShoppingcartId()));
    }

    @Override
    public int delAllCart(Shoppingcart shopingCart) {
        return shoppingcartMapper.deleteAll(shopingCart.getId());
    }

    @Override
    public Shoppingcart getByProductId(Integer valueOf) {
        return shoppingcartMapper.getByproductId(valueOf);
    }

    @Override
    public Shoppingcart getByProductIdAndUserId(int id, Integer productId) {
        return shoppingcartMapper.getByProductIdAndUserId(id, productId);
    }

    @Override
    public List<ShoppingcartVO> getAllShoppingcart(Shoppingcart shopingCart) {
        return shoppingcartMapper.getAllShoppingcart(shopingCart);
    }

}
